<?php
require_once 'Zend/Config/Ini.php';
$globalConfig = new Zend_Config_Ini(__DIR__ . '/../configs/doctrine.ini', 'development');

$resConfig = $globalConfig->resources->doctrine2->toArray();
require_once 'Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();

$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');

//$connectionOptions = array(
//    'driver' => 'pdo_sqlite',
//    'path' => 'database.sqlite'
//);

$em = \Doctrine\ORM\EntityManager::create($resConfig['connection'], $config);
$helpers = array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
);